﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using SdmxMl.Structure;
using Telerik.WinControls.UI;

namespace SmsUsers
{
    public partial class DlgNewUser : Telerik.WinControls.UI.RadForm
    {
        public string UserId { get { return radTextBoxUid.Text; } }
        public string UserName { get { return radTextBoxUserName.Text; } }
        public string UserMail { get { return radMaskedEditBoxMail.Text; } }
        public bool IsGroupAdmin { get { return radCheckBox1.Checked; } }
        public string UserGroup 
        { 
            get 
            {
                GridViewDataRowInfo row = radMultiColumnComboBoxGroup.SelectedItem as GridViewDataRowInfo;
                return row != null ? row.Cells[0].Value.ToString() : string.Empty; } }


        private CodeListType cltCodeGroup;

        public DlgNewUser(CodeListType cltGrp)
        {
            InitializeComponent();
            cltCodeGroup = cltGrp;

            radMultiColumnComboBoxGroup.DataSource = cltCodeGroup.CodeList.GetTableRepresentation();
            radMultiColumnComboBoxGroup.SelectedIndex = 0;
            radMultiColumnComboBoxGroup.EditorControl.Columns[0].Width = 80;
            radMultiColumnComboBoxGroup.EditorControl.Columns[1].Width = 200;
            radMultiColumnComboBoxGroup.EditorControl.AllowColumnReorder = false;

            radTextBoxUid.Select();
        }

        private void radButtonAdd_Click(object sender, EventArgs e)
        {
            if (radTextBoxUid.Text.Trim().Length == 0 ||
                radTextBoxUserName.Text.Trim().Length == 0 ||
                radMaskedEditBoxMail.Text.Trim().Length == 0 ||
                !(radMaskedEditBoxMail.MaskedEditBoxElement.Provider as EMailMaskTextBoxProvider).Validate(radMaskedEditBoxMail.Text))
            {
                RadMessageBox.Show(this, "Please fills required information first!", "Caution", MessageBoxButtons.OK, RadMessageIcon.Error);
            }
            else
                this.DialogResult = DialogResult.OK;
        }
    }
}
